public class point {
    public void sortColors(int[] nums) {
        int len = nums.length;
        int left = -1, right = len, p = 0;
        while (p < right) {
            if (nums[p] == 0) {
                swap(++left, p++, nums);

            } else if (nums[p] == 1) {
                p++;
            } else {
                swap(--right, p, nums);

            }
        }
    }

    private void swap(int i, int j, int[] nums) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
